package gui.media;// Fig. 21.7: gui.media.MediaTest.java
// A simple media player

import javax.swing.*;
import java.net.MalformedURLException;
import java.net.URL;
/*

    This file is part of Logica-Logike.

    Logica-Logike is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation version 3 of the License.

    Logica-Logike is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Logica-Logike.  If not, see <http://www.gnu.org/licenses/>.

 */
public class MediaTest {
    // launch the application
    public static void main(String args[]) {
        // create a file chooser
        JFileChooser fileChooser = new JFileChooser();

        // show open file dialog
        int result = fileChooser.showOpenDialog(null);

        if (result == JFileChooser.APPROVE_OPTION) // user chose a file
        {
            URL mediaURL = null;

            try {
                // get the file as URL
                mediaURL = fileChooser.getSelectedFile().toURL();
            } // end try
            catch (MalformedURLException malformedURLException) {
                System.err.println("Could not create URL for the file");
            } // end catch

            if (mediaURL != null) // only display if there is a valid URL
            {
                JFrame mediaTest = new JFrame("Media Tester");
                mediaTest.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

                MediaPanel mediaPanel = new MediaPanel(mediaURL);
                mediaTest.add(mediaPanel);

                mediaTest.setSize(300, 300);
                mediaTest.setVisible(true);
            } // end inner if
        } // end outer if
    } // end main
} // end class gui.media.MediaTest